export function buildColumn(rows) {
    console.log(rows, "rows");
    if (!rows || rows.length === 0) {
        return []
    }
    let labels = []
    rows.forEach(item => {
        let paramsStr = item.processParameter;
        if (paramsStr == null || paramsStr == "") {
            return
        }
        let list = JSON.parse(paramsStr)
        list.forEach(p => {
            let keys = Object.keys(p)
            labels.push(...keys)
        })
    });
    labels = [...new Set(labels)];
    labels = buildLabels(labels);
    let dataList = reBuildRows(labels, rows)
    return { dataList, labels };
}



function buildLabels(labels) {
    let result = []
    if (labels.length === 0) {
        return result
    }
    labels.forEach(label => {
        label = label.replace(":", "")
        result.push({
            prop: label,
            label: label,
            width: calculateWidth(label)
        })
    })
    return result
}
function calculateWidth(key) {
    return key.length * 22
}

function reBuildRows(labels, rows) {
    if (!labels || labels.length === 0) {
        return rows
    }
    let result = []
    rows.forEach(row => {
        let paramsStr = row.processParameter;
        if (paramsStr == null || paramsStr == "") {
            result.push(row)
            return
        }
        let params = JSON.parse(paramsStr)
        params.forEach(p => {
            let label = Object.keys(p)[0]
            let value = p[label]
            label = label.replace(":", "")
            row[label] = value
        })
        result.push(row)
    })
    return result
}